#ifndef __LOG_SAVE_H__
#define __LOG_SAVE_H__

#include <ros/ros.h>
#include <cln_msgs/LogMsg.h>

using namespace std;

class LogSave{

    public:
    
        /*日志发布
        *    @log_level 日志等级 DEBUG、INFO、WARN、ERROR、FATAL
        */
        void LogPub_ClnMsg(ros::Publisher& log_pub, string log_level, vector<string> msgs, int log_code = 0){
            cln_msgs::LogMsg log_msg;
            log_msg.node_name = ros::this_node::getName();
            log_msg.log_time = ros::Time::now();
            if(log_level == "DEBUG") log_msg.log_level = log_msg.DEBUG;
            else if (log_level == "INFO"){
                for(auto message : msgs) ROS_INFO_STREAM("--> " << message.c_str() << "");
                log_msg.log_level = log_msg.INFO;
            }
            else if (log_level == "WARN"){
                for(auto message : msgs) ROS_WARN_STREAM("--> " << message.c_str() << "");
                log_msg.log_level = log_msg.WARN;
            }
            else if (log_level == "ERROR"){
                for(auto message : msgs) ROS_ERROR_STREAM("--> " << message.c_str() << "");
                log_msg.log_level = log_msg.ERROR;
            }
            else if (log_level == "FATAL"){
                for(auto message : msgs) ROS_FATAL_STREAM("--> " << message.c_str() << "");
                log_msg.log_level = log_msg.FATAL;
            }
            log_msg.log_data = msgs;
            log_msg.log_code = log_code;
            log_pub.publish(log_msg);
        }

        // 日志发布
        void LogPub_ClnMsg(ros::Publisher& log_pub, string log_level, string msg, int log_code = 0){
            vector<string> msgs;
            msgs.emplace_back(msg);
            LogPub_ClnMsg(log_pub, log_level,msgs,log_code);
        }
};


#endif